package com.chuangke.admin.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.chuangke.common.http.HttpResult;
import com.chuangke.system.entity.SysCertificate;
import com.chuangke.system.service.SysCertificateService;

/**
 * 日志控制器
 * @author chuangke
 * @date Oct 29, 2018
 */
@RestController
@RequestMapping("certificate")
public class SysCertificateController {

	@Autowired
	private SysCertificateService sysCertificateService;

	@PreAuthorize("hasAuthority('sys:login')")
	@PostMapping(value="/findPage")
	public HttpResult findPage(@RequestBody Map<String,Object> params) {
		@SuppressWarnings("unchecked")
		List<String> deptIds = (List<String>)params.get("deptId") ;
		return HttpResult.ok(sysCertificateService.findByDept(deptIds,params));
	}
	
	@PreAuthorize("hasAuthority('sys:login')")
	@PostMapping(value="/findlevel")
	public HttpResult findLevel(@RequestBody Map<String,Object> params) {
		@SuppressWarnings("unchecked")
		List<String> deptIds = (List<String>)params.get("deptId") ;
		return HttpResult.ok(sysCertificateService.findByDeptLevel(deptIds,params));
	}

	@PreAuthorize("hasAuthority('sys:login')")
	@PostMapping(value="/delete")
	public HttpResult delete(@RequestBody List<String> ids) {
		sysCertificateService.delete(ids);
		return HttpResult.ok();
	}

	@PreAuthorize("hasAuthority('sys:login')")
	@PostMapping(value="/save")
	public HttpResult save(@RequestBody SysCertificate sysCertificate) {
		List<SysCertificate> list=new ArrayList<>();
		list.add(sysCertificate);
		sysCertificateService.saveOrUpdate(list);
		return HttpResult.ok();
	}

}
